/******************************************************************************
 * Author:      671643387
 * Created:     2016/9/28
 *****************************************************************************/

var clone = require('clone');
var Enum = require('./Enum.js');
var util = require("util");

function HupaiSt() {
    this.pair = 0;
    this.sequences = [];
}

/**
 * 带混玩法，检查玩家能否胡牌
 * @param player    玩家数据
 * @param card      牌
 */
function checkType1_Hupai(player, card) {

    // 检查玩家手牌能否胡牌
    var handCards = clone(player.getHandCards());

    handCards.add(card);

    var mixCard = player.mixCard;
    //var mixNum = handCards.getMixCardNum(mixCard);

    // 检查是不是十三幺
    var ziPaiNum = checkShiSanYao(handCards, mixCard);
    if (ziPaiNum) {
        // 检查带的风是否全
        if(ziPaiNum == 7){
            player.isWindAll = true;
        }
        return Enum.HupaiType.METHOD_13_PAIRS;
    }
    // 检查是不是7对
    var is7Dui = checkMix7Dui(handCards, mixCard);
    if (is7Dui) {
        return Enum.HupaiType.METHOD_7_PAIRS;
    }

    // 通用检查
    var huiPaiArr = checkMixCanHupai(handCards, mixCard);
    if (huiPaiArr.length > 0) {
        return Enum.HupaiType.METHOD_PINHUI_PAIRS;
    }
    return 0;
}

/**
 * 258做将玩法，检查玩家能否胡牌
 * @param player    玩家数据
 * @param card      牌
 */
function checkType2_Hupai(player, card) {
    // 检查玩家手牌能否胡牌
    var handCards = clone(player.getHandCards());

    handCards.add(card);
    // 检查是不是7对
    var is7Dui = check7Dui(handCards);
    if (is7Dui) {
        return Enum.HupaiType.METHOD_7_PAIRS;
    }
    // 通用检查
    var huiPaiArr = checkCanHupai(handCards);
    if (huiPaiArr.length > 0) {
        for(var pos = 0; pos < huiPaiArr.length; pos++){
            var temp = huiPaiArr[pos];
            // 将牌是258
            if(temp && (temp.pair == 2 || temp.pair == 5 || temp.pair == 8 || temp.pair == (9 + 2) || temp.pair == (9 + 5) || temp.pair == (9 + 8) || temp.pair == (18 + 2) || temp.pair == (18 + 5) || temp.pair == (18 + 8))){
                //player.pushHuPaiType(Enum.HupaiType.METHOD_PINHUI_PAIRS);
                return Enum.HupaiType.METHOD_PINHUI_PAIRS;
            }
        }
        return 0;
    }
    return 0;
}
function checkShiSanYao(handCards, mixCard) {
    var isJiangPai = false;
    var effectiveIdx = handCards.getSynEffectiveIdx();
    // 检查 13
    if ((handCards.num < 14) || effectiveIdx < 11) {
        return 0;
    }
    var cards = handCards.cards;
    // 查找将牌，
    for(var iCard = 0; iCard < cards.length; ++iCard){
        if(cards[iCard].num > 2 && cards[iCard].value != mixCard){
            return 0;
        }
        var card = cards[iCard];
        if(card.value == mixCard){
            continue;
        }
        // 将牌多了，
        if(isJiangPai && cards[iCard].num > 1){
            return 0;
        }
        if (cards[iCard].num == 2 && !isJiangPai) {
            isJiangPai = true;
        }
    }
    var mixPai = 0;
    var ziPai = 0;
    var wanZi = [];
    var tiaoZi = [];
    var tongZi = [];
    // 牌型分组
    for (var iCard = 0; iCard < cards.length; ++iCard) {
        if (cards[iCard].num == 0) {
            continue;
        }
        // 混
        if (cards[iCard].value == mixCard) {
            mixPai = cards[iCard].num;
            continue;
        }
        // 字
        if (cards[iCard].value > 27) {
            ziPai += 1;;
            continue;
        }
        var typeValue = parseInt((cards[iCard].value - 1) / 9);
        // 筒
        if (typeValue == 0) {
            tongZi.push(cards[iCard].value);
        } else if (typeValue == 1) { // 条
            tiaoZi.push(cards[iCard].value);
        } else if (typeValue == 2) { // 万
            wanZi.push(cards[iCard].value);
        }
    }
    // 其中一门牌多于三段
    if(wanZi.length > 3 || tiaoZi.length > 3 || tongZi.length > 3){
        return 0;
    }
    // 筒
    if(tongZi.length == 3  || ( 3 - tongZi.length <= mixPai )){
        if(tongZi.length < 3){
            mixPai -= (3 - tongZi.length);
        }
        if(tongZi.length == 3 && (tongZi[2] - tongZi[1] < 3 || tongZi[1] - tongZi[0] < 3 ) ){
            return 0;
        }
        if(tongZi.length == 2 && (tongZi[1] - tongZi[0] < 3)){
            return 0;
        }
    }else if(tongZi.length != 0){
        return 0;
    }
    // 条
    if(tiaoZi.length == 3 || ( 3 - tiaoZi.length <= mixPai )){
        if(tiaoZi.length < 3){
            mixPai -= (3 - tiaoZi.length);
        }
        if(tiaoZi.length == 3 && (tiaoZi[2] - tiaoZi[1] < 3 || tiaoZi[1] - tiaoZi[0] < 3 ) ){
            return 0;
        }
        if(tiaoZi.length == 2 && (tiaoZi[1] - tiaoZi[0] < 3)){
            return 0;
        }
    }else if(tiaoZi.length != 0){
        return 0;
    }
    // 万
    if(wanZi.length == 3 || ( 3 - wanZi.length <= mixPai )){
        if(wanZi.length < 3){
            mixPai -= (3 - wanZi.length);
        }
        if(wanZi.length == 3 && (wanZi[2] - wanZi[1] < 3 || wanZi[1] - wanZi[0] < 3 ) ){
            return 0;
        }
        if(wanZi.length == 2 && (wanZi[1] - wanZi[0] < 3)){
            return 0;
        }
    }else if(wanZi.length != 0){
        return 0;
    }

    // 没有将牌，用一张混牌
    if(!isJiangPai && mixPai > 0){
        isJiangPai = true;
        // 减一张混牌，
        mixPai -= 1;

    }
    // 检查 字牌数量, 不够用混牌补
    if((ziPai != 4 || ziPai != 7) && mixPai > 0 ){
        ziPai += mixPai;
        mixPai = 0;
    }
    // 没有将牌， 或者混牌没有用完, 或者字牌数量不对
    if(!isJiangPai || mixPai > 0 || (ziPai != 4 && ziPai != 7)){
        return 0;
    }
    // 最后条件都满足，
    return ziPai;
}

function checkoutMix13Yao(handCards, hpSt, hpArr, mixCard, mixNum) {
    if (handCards.num == 0) {
        hpArr.push(hpSt);
        return;
    }
    var cards = handCards.cards;
    for (var iCard = 0; iCard < cards.length; ++iCard) {
        var card = cards[iCard];

        if (card.num < 1) {
            continue;
        }
        // 当前元素num大于一退出 ， 小于28 & 当前元素对九取余 大于3退出
        if (card.num > 1 || (card.value < 28 && card.value % 9 > 3 )) {
            return;
        }
        console.log(util.format("checkoutMix13Yao %d   %d   ====  %j", card.value, cards[mixCard - 1].num, hpSt));
        // 混牌没有，
        if((card.value == mixCard && mixNum < 1) || (card.num == 0 && mixNum < 1)){
            continue;
        }

        if(card.value == mixCard && mixNum > 0){
            --mixNum;
            handCards.decCard(mixCard, 1);
        }

        if(card.value < 28){
            // 1 - 27   筒 条 万
            //1  2  3

            // 中间1牌
            if(cards[iCard + 1].value != mixCard && cards[iCard + 1].num > 0){
                return;
            }
            // 中间2牌
            if(cards[iCard + 2].value != mixCard && cards[iCard + 2].num > 0){
                return;
            }
            // 4 5 6
            if ((cards[iCard + 3].num == 0 && mixNum<  0) || cards[iCard + 3].num != 1){
                return;
            }
            // 中间1牌
            if(cards[iCard + 4].value != mixCard && cards[iCard + 4].num > 0){
                return;
            }
            // 中间2牌
            if(cards[iCard + 5].value != mixCard && cards[iCard + 5].num > 0){
                return;
            }
            // 7 8 9
            if ((cards[iCard + 6].num == 0 && mixNum<  0) || cards[iCard + 6].num != 1){
                return;
            }

            hpSt.sequences.push(iCard.value);
        }else{
            hpSt.sequences.push(iCard.value);
        }
    }
}

function checkMixCanHupai(handCards, mixCard) {
    // 检查 3n + 2
    if ((handCards.num - 2) % 3 != 0) {
        return false;
    }

    var hpArr = [];

    var cards = handCards.cards;
    for (var iCard = 0; iCard < cards.length; ++iCard) {
        if (cards[iCard].num == 0) {
            continue;
        }
        var newMixNum = cards[mixCard - 1].num;
        if(cards[iCard].value == mixCard){
            newMixNum -= 1;
        }
        // 将牌是万能牌，要求本身数量大于等于2张。               将牌用一张混牌代替，                     或者没有混牌，将牌需要2张
        if ((cards[iCard].value == mixCard && newMixNum >= 2) || (newMixNum > 0 && cards[iCard].num >= 1) || cards[iCard].num >= 2) {

            var hpSt = new HupaiSt();
            hpSt.pair = cards[iCard].value; // 将牌

            var newHandCards = clone(handCards);
            var num = 0;
            // 检查有没有用到混牌，用到者减少一张
            if(cards[iCard].value == mixCard && newMixNum > 1){
                newHandCards.decCard(mixCard, 2);
            }else if(cards[iCard].num == 1 && newMixNum > 0){
                newHandCards.decCard(mixCard, 1);
                newHandCards.decCard(cards[iCard].value, 1);
            }else{
                newHandCards.decCard(cards[iCard].value, 2);
            }
            // 扣除2张将牌
            checkoutMix3(newHandCards, hpSt, hpArr, mixCard);
            //console.log(util.format("\n"));

            //只需要检查能否胡牌， 不用有多少种胡牌牌型
            if(hpArr.length > 0){
                break;
            }
        }
    }
    return hpArr;
}
function checkoutMix3(handCards, hpSt, hpArr, mixCard) {
    if (handCards.num == 0) {
        hpArr.push(hpSt);
        return;
    }
    var tempCard = handCards.getSynEffectiveData();
    //console.log(util.format("%j | %j", hpArr, tempCard));
    var cards = handCards.cards;
    for (var iCard = 0; iCard < cards.length; ++iCard) {

        if ((cards[iCard].num == 0/* && cards[iCard].value % 9 != 7*/)) {
            continue;
        }
        var card = cards[iCard];
        var newMixNum = cards[mixCard - 1].num;
        if(card.value == mixCard && newMixNum > 0){
            newMixNum -= 1;
        }
        /*if(cards[iCard].num == 0 && newMixNum < 1){
            continue;
        }*/

        //console.log(util.format("%d   %d   ====  %j", card.value, cards[mixCard - 1].num, hpSt));
        if ( card.value < 28 && (((newMixNum > 0 && card.num < 2) || card.num <= 2) || card.num == 4)) {
            var card2 = cards[iCard + 1];
            var card3 = cards[iCard + 2];
            if (!card2 || !card3) {
                return;
            }
            if(card.num != 4 && 3 - card.num <= newMixNum){
                // 作为暗刻
                var newHandCards = clone(handCards);
                var newHpSt = clone(hpSt);
                if(card.value == mixCard){
                    newHandCards.decCard(mixCard, 3);
                }else {
                    newHandCards.decCard(mixCard, 3 - card.num);
                    newHandCards.decCard(card.value, card.num);
                }
                newHpSt.sequences.push([card.value, card.value, card.value]);
                checkoutMix3(newHandCards, newHpSt, hpArr, mixCard);
            }
            // 当前牌数量不够，混牌数量也不够，
            if ((card2.num == 0 && newMixNum  < 1) || (card3.num == 0 && newMixNum  < 1) || (card2.num == 0 && card3.num == 0 && newMixNum < 2)) {
                if(card.value == mixCard){
                    continue;
                }else {
                    return;
                }
            }
            // 当前牌等于混牌， 检查混牌数量是否够， 够就可以拿去组合，并且减去相应的混牌张数
            if ((card2.value == mixCard && newMixNum < 1) || (card3.value == mixCard && newMixNum < 1)) {
                return;
            }

            var type = Math.floor((card.value - 1) / 9);
            var type2 = Math.floor((card2.value - 1) / 9);
            var type3 = Math.floor((card3.value - 1) / 9);
            if (!(type == type2 && type == type3)) {
                return;
            }

            // 有混牌，或者当前牌数量是零就用混牌
            if (card.num < 1 && newMixNum > 0) {
                newMixNum -= 1;
                handCards.decCard(mixCard, 1);
            }
            // 有混牌，或者当前牌数量是零就用混牌
            if (card2.value == mixCard && card2.num < 1 && newMixNum > 0) {
                newMixNum -= 1;
                handCards.decCard(mixCard, 1);
            }
            // 有混牌，或者当前牌数量是零就用混牌
            if (card3.value == mixCard && card3.num < 1 && newMixNum > 0) {
                newMixNum -= 1;
                handCards.decCard(mixCard, 1);
            }
            // 有混牌，或者当前牌数量是零就用混牌
            if (card2.num < 1 && newMixNum > 0) {
                newMixNum -= 1;
                handCards.decCard(mixCard, 1);
            }
            // 有混牌，或者当前牌数量是零就用混牌
            if (card3.num < 1 && newMixNum > 0) {
                newMixNum -= 1;
                handCards.decCard(mixCard, 1);
            }

            hpSt.sequences.push([card.value, card2.value, card3.value]);

            if (card.value == mixCard) {
                newMixNum -= 1;
                handCards.decCard(mixCard, 1);
            }
            if (card.num > 0) {
                handCards.decCard(card.value, 1);
            }
            if (card2.num > 0) {
                handCards.decCard(card2.value, 1);
            }
            if (card3.num > 0) {
                handCards.decCard(card3.value, 1);
            }
            checkoutMix3(handCards, hpSt, hpArr, mixCard);
            break;
        } else if (card.num == 3 || 3 - card.num <= newMixNum) {
            // 检查能否和后面构成顺子
            var card2 = cards[iCard + 1];
            var card3 = cards[iCard + 2];
            if(card2 && card3) {
                var dec2Num = Math.min(card2.num, 3);
                var dec3Num = Math.min(card3.num, 3);

                if (card.value == mixCard) {
                    newMixNum -= 3;
                }
                // 如果不够就拿混牌替
                if (card2 && card3 && ( (dec2Num + dec3Num + newMixNum) >= 6) && card3.value < 28) {

                    // 作为顺子
                    var newHandCards = clone(handCards);
                    var newHpSt = clone(hpSt);

                    var decMixCardNum = 6 - dec2Num + dec3Num;

                    newHpSt.sequences.push([card.value, card2.value, card3.value]);
                    newHpSt.sequences.push([card.value, card2.value, card3.value]);
                    newHpSt.sequences.push([card.value, card2.value, card3.value]);

                    newHandCards.decCard(card.value, 3);
                    newHandCards.decCard(card2.value, dec2Num);
                    newHandCards.decCard(card3.value, dec3Num);

                    newHandCards.decCard(mixCard, decMixCardNum);
                    newMixNum -= decMixCardNum;

                    checkoutMix3(newHandCards, newHpSt, hpArr, mixCard);
                }
            }
            // 作为暗刻
            hpSt.sequences.push([card.value, card.value, card.value]);
            handCards.decCard(card.value, 3);
            checkoutMix3(handCards, hpSt, hpArr, mixCard);
            break;
        }
    }
}

function checkCanHupai(handCards) {
    // 检查 3n + 2
    if ((handCards.num - 2) % 3 != 0) {
        return false;
    }

    var hpArr = [];

    var cards = handCards.cards;
    for (var iCard = 0; iCard < cards.length; ++iCard) {
        if (cards[iCard].num == 0) {
            continue;
        }

        if (cards[iCard].num >= 2) {

            var hpSt = new HupaiSt();
            hpSt.pair = cards[iCard].value; // 将牌

            var newHandCards = clone(handCards);

            // 扣除2张将牌
            newHandCards.decCard(cards[iCard].value, 2);
            checkout3(newHandCards, hpSt, hpArr);
            //只需要检查能否胡牌， 不用有多少种胡牌牌型
            if(hpArr.length > 0){
                break;
            }
        }
    }

    return hpArr;
}

function checkout3(handCards, hpSt, hpArr) {
    if (handCards.num == 0) {
        hpArr.push(hpSt);
        return;
    }

    var cards = handCards.cards;
    for (var iCard = 0; iCard < cards.length; ++iCard) {
        if (cards[iCard].num == 0) {
            continue;
        }

        var card = cards[iCard];
        var temp = cards[iCard + 2];
        if ((card.num <= 2 || card.num == 4) && (temp && temp.value < 28) ) {
            var card2 = cards[iCard + 1];
            var card3 = cards[iCard + 2];

            if (!card2 || !card3) {
                return;
            }
            if (card2.num == 0 || card3.num == 0) {
                return;
            }
            var type = Math.floor((card.value - 1) / 9);
            var type2 = Math.floor((card2.value - 1) / 9);
            var type3 = Math.floor((card3.value - 1) / 9);
            if (!(type == type2 && type == type3)) {
                return;
            }

            hpSt.sequences.push([card.value, card2.value, card3.value]);

            handCards.decCard(card.value, 1);
            handCards.decCard(card2.value, 1);
            handCards.decCard(card3.value, 1);
            checkout3(handCards, hpSt, hpArr);
            break;
        } else if (card.num == 3) {
            // 检查能否和后面构成顺子
            var card2 = cards[iCard + 1];
            var card3 = cards[iCard + 2];

            if ((card2 && card3) && (card2.num == 3 && card3.num == 3) && (card3.value < 28)) {
                // 作为顺子
                var newHandCards = clone(handCards);
                var newHpSt = clone(hpSt);

                newHpSt.sequences.push([card.value, card2.value, card3.value]);

                newHandCards.decCard(card.value, 1);
                newHandCards.decCard(card2.value, 1);
                newHandCards.decCard(card3.value, 1);
                checkout3(newHandCards, newHpSt, hpArr);
            }

            // 作为暗刻
            hpSt.sequences.push([card.value, card.value, card.value]);
            handCards.decCard(card.value, 3);
            checkout3(handCards, hpSt, hpArr);
            break;
        }
    }
}

/**
 * 检查玩家的牌是不是7对
 * @param handCards
 */
function checkMix7Dui(handCards, mixCard) {
    var numDuiZi = 0;
    var mixNum = 0;
    var singleNum = 0;
    var cards = handCards.cards;
    for (var iCard = 0; iCard < cards.length; ++iCard) {
        var temp = cards[iCard];
        if (temp.num == 0) {
            continue;
        }
        if(temp.value == mixCard){
            mixNum = temp.num;
            continue;
        }
        if(temp.num == 1){
            singleNum += 1;
        }else if(temp.num == 2){
            numDuiZi += 1;
        }else if(temp.num == 3){
            numDuiZi += 1;
            singleNum += 1;
        }else if(temp.num == 4){
            numDuiZi += 2;
        }
    }
    // 混牌补不够单牌
    if(mixNum < singleNum){
        return false;
    }else{
        mixNum -= singleNum;
        numDuiZi += singleNum;
        singleNum = 0;
    }
    // 混牌有单
    if(mixNum % 2 != 0){
        return false;
    }
    numDuiZi += parseInt(mixNum / 2);
    mixNum = 0;
    if(numDuiZi != 7 || singleNum != 0){
        return false;
    }
    // 条件满足
    return true;
}

/**
 * 检查玩家的牌是不是7对
 * @param handCards
 */
function check7Dui(handCards) {
    var numDuiZi = 0;
    var cards = handCards.cards;

    for (var iCard = 0; iCard < cards.length; ++iCard) {
        if (cards[iCard].num == 0) {
            continue;
        }

        if (cards[iCard].num == 2) {
            numDuiZi += 1;
        } else if (cards[iCard].num == 4) {
            numDuiZi += 2;
        }
    }

    return (numDuiZi == 7);
}
/**
 * 检查玩家是否听牌
 * @param player    玩家数据
 */
function checkHearPai(player, roomType, selectWind) {
    var isTingPai = false;
    var card = 0;
    if(1 == roomType){
        // 检查玩家手牌能否听牌
        for(var key = 1; key <= 34; ++key) {
            card = +key;
            if (checkType1_Hupai(player, card) != 0) {
                isTingPai = true;
                break;
            }
            card = 0;
        }
    }else if( 2 == roomType){
        var CardNum = 27;
        if(selectWind){CardNum = 34;}
        // 检查玩家手牌能否听牌
        for(var key = 1; key <= CardNum; ++key) {
            card = +key;
            if (checkType2_Hupai(player, card) != 0) {
                isTingPai = true;
                break;
            }
            card = 0;
        }
    }
    return isTingPai;
}
exports.checkHearPai = checkHearPai;
exports.checkType1_Hupai = checkType1_Hupai;
exports.checkType2_Hupai = checkType2_Hupai;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 测试胡牌算法使用

var MAX_CARDS = 27;

function HandCards() {
    this.num = 0;           // 当前牌总数
    this.cards = [];        // 玩家手牌

    this.init();
}
HandCards.prototype = {
    // 初始化
    init: function() {
        for (var iCard = 0; iCard < MAX_CARDS; ++iCard) {
            this.cards[iCard] = {
                value : iCard + 1,
                num : 0,
            };
        }
    },

    // 添加手牌
    adds: function(cards) {
        var _me = this;
        cards.forEach(function(card){
            var value = (card.type - 1) * 9 + card.value;
            var newCard = _me.cards[value - 1];
            newCard.num += 1;
            _me.cards[value - 1] = newCard;
            _me.num += 1;
        });
    },

    // 增加一张手牌
    add: function(card) {
        var myCard = this.cards[card.value - 1];
        myCard.num += 1;
        this.num += 1;
    },

    // 获取手牌有几个和这张牌一样的牌
    hasSame: function(card) {
        var myCard = this.cards[card - 1];
        return myCard.num;
    },

    // 减少手牌
    decCard: function(card, num) {
        var myCard = this.cards[card - 1];
        myCard.num -= num;
        this.num -= num;
    },

    // 获取手牌同步数据
    getSyncData: function() {
        return this.cards;
    },
    getSynEffectiveData: function () {
        var cards = [];
        for(var pos in this.cards){
            if(!this.cards.hasOwnProperty(pos)){
                continue;
            }
            if(this.cards[pos].num>0){
                cards.push(this.cards[pos]);
            }
        }
        return cards;
    },
    // 获取还剩余几张手牌
    getRemainCardNum: function() {
        return this.num;
    },
    getSynEffectiveIdx: function () {
        var num = 0;
        for(var pos in this.cards){
            if(!this.cards.hasOwnProperty(pos)){
                continue;
            }
            if(this.cards[pos].num>0){
                ++num;
            }
        }
        return num;
    },
};

var handshisanyaoCards = new HandCards();
handshisanyaoCards.num = 8;
handshisanyaoCards.cards = [
    {"value": 1,"num": 0    },
    {"value": 2,"num": 0   },
    {"value": 3,"num": 0    },
    {"value": 4,"num": 0    },
    {"value": 5,"num": 1    },
    {"value": 6,"num": 0    },
    {"value": 7,"num": 3    },
    {"value": 8,"num": 0   },
    {"value": 9,"num": 0    },
    {"value": 10,"num": 0    },
    {"value": 11,"num": 0    },
    {"value": 12,"num": 0    },
    {"value": 13,"num": 0   },
    {"value": 14,"num": 0    },
    {"value": 15,"num": 1    },
    {"value": 16,"num": 1    },
    {"value": 17,"num": 0    },
    {"value": 18,"num": 0    },
    {"value": 19,"num": 0    },
    {"value": 20,"num": 0    },
    {"value": 21,"num": 0    },
    {"value": 22,"num": 0    },
    {"value": 23,"num": 2    },
    {"value": 24,"num": 0    },
    {"value": 25,"num": 0    },
    {"value": 26,"num": 0    },
    {"value": 27,"num": 0    },
    {"value": 28,"num": 0    },
    {"value": 29,"num": 0    },
    {"value": 30,"num": 0    },
    {"value": 31,"num": 0    },
    {"value": 32,"num": 0    },
    {"value": 33,"num": 0    },
    {"value": 34,"num": 0    }
];
var hand7DuiCards = new HandCards();
hand7DuiCards.num = 14;
hand7DuiCards.cards = [
    { "value": 1, "num": 1    },
    { "value": 2,"num": 0    },
    {"value": 3,"num": 0    },
    {"value": 4,"num": 2    },
    {"value": 5,"num": 0    },
    {"value": 6,"num": 1    },
    {"value": 7,"num": 2    },
    {"value": 8,"num": 0    },
    {"value": 9,"num": 0    },
    {"value": 10,"num": 0    },
    {"value": 11,"num": 1    },
    {"value": 12,"num": 0    },
    {"value": 13,"num": 1    },
    {"value": 14,"num": 0    },
    {"value": 15,"num": 2    },
    {"value": 16,"num": 0    },
    {"value": 17,"num": 0    },
    {"value": 18,"num": 0    },
    {"value": 19,"num": 0    },
    {"value": 20,"num": 0    },
    {"value": 21,"num": 1    },
    {"value": 22,"num": 0    },
    {"value": 23,"num": 0    },
    {"value": 24,"num": 3    },
    {"value": 25,"num": 0    },
    {"value": 26,"num": 0    },
    {"value": 27,"num": 0    },
    {"value": 28,"num": 0    },
    {"value": 29,"num": 0    },
    {"value": 30,"num": 0    },
    {"value": 31,"num": 0    },
    {"value": 32,"num": 0    },
    {"value": 33,"num": 0    },
    {"value": 34,"num": 0    }
];
var handMixCards = new HandCards();
handMixCards.num = 13;
handMixCards.cards = [
    { "value": 1, "num": 0    },
    { "value": 2,"num": 0    },
    {"value": 3,"num": 1    },
    {"value": 4,"num": 1    },
    {"value": 5,"num": 1    },
    {"value": 6,"num": 0    },
    {"value": 7,"num": 0    },
    {"value": 8,"num": 0    },
    {"value": 9,"num": 0    },
    {"value": 10,"num": 0    },
    {"value": 11,"num": 0    },
    {"value": 12,"num": 0    },
    {"value": 13,"num": 0    },
    {"value": 14,"num": 0    },
    {"value": 15,"num": 0    },
    {"value": 16,"num": 0    },
    {"value": 17,"num": 2    },
    {"value": 18,"num": 0    },
    {"value": 19,"num": 0    },
    {"value": 20,"num": 0    },
    {"value": 21,"num": 0    },
    {"value": 22,"num": 0    },
    {"value": 23,"num": 1    },
    {"value": 24,"num": 1    },
    {"value": 25,"num": 1    },
    {"value": 26,"num": 2    },
    {"value": 27,"num": 0    },
    {"value": 28,"num": 0    },
    {"value": 29,"num": 0    },
    {"value": 30,"num": 0    },
    {"value": 31,"num": 0    },
    {"value": 32,"num": 0    },
    {"value": 33,"num": 0    },
    {"value": 34,"num": 0    }
];
/*var arr = checkCanHupai(handshisanyaoCards, 5);
//var arr = checkShiSanYao(handshisanyaoCards, 13);
console.log(arr);
var arr = checkMix7Dui(hand7DuiCards, 24);
console.log(arr);
var arr = checkMixCanHupai(handMixCards, 23);*/
